package cn.zhku.edu.productservice.controller;

import cn.zhku.edu.feign.common.R;

import cn.zhku.edu.productservice.service.ProductServies;
import cn.zhku.edu.productservice.service.SearchServies;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author clk
 * @Date:2021/9/13  10:17
 **/
@RestController
@CrossOrigin
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private SearchServies searchServies;
    @Autowired
    private ProductServies productServies;

    @RequestMapping("/Bytid")
    public R getCate(int tid) {
        return new R(200, "访问成功！", searchServies.selectAllShop(tid));
    }

    @RequestMapping("/Bytname")
    public R getCateintroduce(String typename) {
        return new R(200, "访问成功", searchServies.selectLikeConcatByTypeName(typename));
    }

    @RequestMapping("/Byfilterlist")
    public R getProduct(String[] filterlist,int tid) {
        return new R(200, "访问成功", productServies.selectAllFilter(filterlist,tid));
    }

    @RequestMapping("/selectBygname")
    public R getProductByname(String gname) {
        return new R(200, "访问成功", searchServies.selectAllBygname(gname));
    }

    @GetMapping("/suggestion")
    public R getSuggestion(@RequestParam String key) {
        return new R(200,"检索建议",searchServies.getSuggestion(key));
    }
}
